//
//  EPMEmotionCell.m
//  WeiBoByOC
//
//  Created by 马继鵬 on 17/4/7.
//  Copyright © 2017年 7TH. All rights reserved.
//

#import "EPMEmotionCell.h"
#import "EPMEmotionModel.h"
#import "EPMEmotionBtn.h"
@interface EPMEmotionCell()
@property (weak,nonatomic) UILabel* label;
@property (strong,nonatomic) NSMutableArray* btnList;
@end
@implementation EPMEmotionCell
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]){
        [self setupUI];
    }
    return self;
}

- (NSMutableArray*)btnList{
    if (_btnList == nil){
        _btnList = [NSMutableArray new];
    }
    return  _btnList;
}
#pragma
#pragma-设置UI
- (void)setupUI{
    UILabel* label = [UILabel EPM_Title:nil textColor:[UIColor redColor] fontSize:FONTSIZEHUG];
    _label = label;
    [self.contentView addSubview:label];
    label.numberOfLines = 2;
    label.textAlignment = NSTextAlignmentCenter;
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.offset(0);
    }];
    
    //设置btn排序
    CGFloat itemW = screenWidth/7;
    CGFloat itemH = self.frame.size.height / 3;
    for (int i = 0 ; i < 20;i++){
        CGRect frame = CGRectMake(itemW* (i%7), itemH * (i/7), itemW, itemH);
        EPMEmotionBtn* btn = [[EPMEmotionBtn alloc]initWithFrame:frame];
        [btn addTarget:self  action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [self.btnList addObject:btn];
        [self.contentView addSubview:btn];
    }
   

    
}

- (void)btnClicked:(EPMEmotionBtn*)sender{
    //将按键的model属性做为参数发送消息
    [[NSNotificationCenter defaultCenter]postNotificationName:EMOTIONBTNCLICKEDINFO object:sender.emotionModel];
    
    
    
}


- (void)setIndexPath:(NSIndexPath *)indexPath{
    _indexPath = indexPath;
    self.label.text = [NSString stringWithFormat:@"第%zd组\n 第%zd个",indexPath.section,indexPath.item];
}


- (void)setEmotionList:(NSArray<EPMEmotionModel *> *)emotionList
{
    _emotionList = emotionList;
    //防止复用显示
    for (UIButton * btn in self.btnList){
        btn.hidden = YES;
    }
    for(int i = 0; i < self.emotionList.count; i ++){
        EPMEmotionBtn* btn = self.btnList[i];
        btn.emotionModel = self.emotionList[i];
        btn.hidden = NO;
    }
    
}


@end
